package com.sunshine.binding;

import com.sunshine.session.SqlSession;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.util.Map;

/**
 * @author Mokairui
 * @description
 * @since 2022/10/30
 */
public class MapperProxy<T> implements InvocationHandler {
    
    private SqlSession sqlSession;
    private final Class<T> mapperInterfaces;

    public MapperProxy(SqlSession sqlSession, Class<T> mapperInterfaces) {
        this.sqlSession = sqlSession;
        this.mapperInterfaces = mapperInterfaces;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        if (Object.class.equals(method.getDeclaringClass())) {
            return method.invoke(method, args);
        }
        return sqlSession.selectOne(method.getName(), args);
    }
}
